home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
051-075
/
071
/
amibas
/
comp
(
.txt
)
< prev
next >
Wrap
AmigaBASIC Source Code
|
1995-03-13
|
3KB
|
84 lines
'" Comp , Compare Two Files
'" P. Kittel, CBM Ffm, Start 11.01.87, 24.02.87
PRINT "Comp - Compare Two Files.":PRINT
PRINT "Filename 1 ?":LINE INPUT f1$:PRINT
PRINT "Filename 2 ?":LINE INPUT f2$
PRINT
PRINT "Show contents (mark differences) (y/n) ? ";
a$="":WHILE a$<>"y" AND a$<>"n":a$=INKEY$:WEND
fi=a$="y":PRINT a$:PRINT
PRINT "Abort process with q key, pause with any.":PRINT
OPEN f1$ FOR INPUT AS 1:l1=LOF(1)
OPEN f2$ FOR INPUT AS 2:l2=LOF(2)
fuu=0:IF l1<>l2 THEN PRINT :PRINT "Files unequal, different in length!":PRINT :fuu=-1
n=1000:n1=0:n2=0:fu=0:m=0:m1$="":m2$="":mn=0
WHILE n1<l1 AND (fu=0 OR fi) AND a$<>"q" '" loop for file 1
a$=INKEY$:IF a$<>"" THEN GOSUB taste '" pause or abort?
IF n1+n>l1 THEN n=l1-n1
i1$=INPUT$(n,1) '" read from files
IF n2+n>l2 THEN
IF n2<l2 THEN i2$=INPUT$(l2-n2,2) :ELSE i2$=""
ELSE
i2$=INPUT$(n,2)
END IF
n3=n1:n1=n1+n:n2=n2+n
IF fi THEN '" show contents as hexdump
FOR j=1 TO LEN(i1$)
IF m>15 THEN GOSUB inhalt
m1$=m1$+MID$(i1$,j,1)
m2$=m2$+MID$(i2$,j,1)
m =m+1
NEXT
END IF
IF i1$<>i2$ AND fu=0 THEN '" tell when unequal
i=1
FOR j=1 TO LEN(i1$)
IF MID$(i1$,j,1)<>MID$(i2$,j,1) THEN i=j:j=1e+09
NEXT
PRINT "Files unequal from byte";i+n3
fu=-1
END IF
WEND
IF fi THEN IF m>0 THEN GOSUB inhalt '" show rest of contents
IF fu=0 AND fuu=0 THEN PRINT :PRINT "Files equal." :ELSE PRINT :PRINT "Files unequal."
CLOSE 1:CLOSE 2
END
inhalt: '" subroutine for hexdump
a$=INKEY$:IF a$<>"" THEN GOSUB taste
PRINT RIGHT$("000"+HEX$(mn),4);" "; '" address in file
FOR jj=1 TO LEN(m1$) '" loop for one line
j1$=MID$(m1$,jj,1):j2$=MID$(m2$,jj,1)
IF j1$<>j2$ THEN COLOR 3 '" mark differences by color
PRINT RIGHT$("0"+HEX$(ASC(j1$)),2);" "; '" single byte in hex
COLOR 1
NEXT
PRINT SPC(2+3*(16-LEN(m1$))); '" show also as character on the right
FOR jj=1 TO LEN(m1$)
j1=ASC(MID$(m1$,jj,1))
IF j1<32 THEN
COLOR 2:PRINT CHR$(j1+64);:COLOR 1 '" mark control chars by color
ELSE
PRINT CHR$(j1);
END IF
NEXT
PRINT
mn=mn+LEN(m1$):m1$="":m2$="":m=0
RETURN
taste: '" subroutine for pause by key pressed
IF a$<>"q" THEN a$="":WHILE a$="":a$=INKEY$:WEND '" wait for next key
IF a$="q" THEN '" q key for end of program
IF fu=0 AND fuu=0 THEN PRINT :PRINT "Files equal." :ELSE PRINT :PRINT "Files unequal."
CLOSE 1:CLOSE 2
END
END IF
RETURN